package com.autumn.sms.client;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.autumn.util.ExceptionUtils;
import com.autumn.util.StringUtils;
import com.autumn.validation.ValidationUtils;

/**
 * 短信发送消息
 * 
 * @author 老码农
 *
 *         2018-01-11 12:18:37
 */
public class SmsSendMessage implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2769698872843708141L;
	private String messageId;
	private String mobilePhone;
	private String templateCode;
	private Map<String, String> params;

	/**
	 * 
	 */
	public SmsSendMessage() {
		this.params = new HashMap<>();
	}

	/**
	 * 获取消息id
	 * 
	 * @return
	 *
	 */
	public String getMessageId() {
		return messageId;
	}

	/**
	 * 设置消息id
	 * 
	 * @param messageId
	 *            消息id
	 *
	 */
	public void setMessageId(String messageId) {
		this.messageId = messageId;
	}

	/**
	 * 获取手机号码
	 * 
	 * @return
	 *
	 */
	public String getMobilePhone() {
		return mobilePhone;
	}

	/**
	 * 设置手机号码
	 * 
	 * @param mobilePhone
	 *            手机号码
	 *
	 */
	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}

	/**
	 * 获取模板代码
	 * 
	 * @return
	 *
	 */
	public String getTemplateCode() {
		return templateCode;
	}

	/**
	 * 设置模板代码
	 * 
	 * @param templateCode
	 *            模板代码
	 *
	 */
	public void setTemplateCode(String templateCode) {
		this.templateCode = templateCode;
	}

	/**
	 * 获取参数集合
	 * 
	 * @return
	 *
	 */
	public Map<String, String> getParams() {
		return params;
	}

	/**
	 * 设置参数集合
	 * 
	 * @param params
	 *
	 */
	public void setParams(Map<String, String> params) {
		this.params = params;
	}

	/**
	 * 验证
	 * 
	 * @param isVerificationCode
	 *
	 */
	public void validate(boolean isVerificationCode) {
		if (StringUtils.isNullOrBlank(this.getMobilePhone())) {
			ExceptionUtils.throwInvalidCastException("mobilePhone 不能为空。");
		}
		if (!isVerificationCode && StringUtils.isNullOrBlank(this.getTemplateCode())) {
			ExceptionUtils.throwInvalidCastException("templateCode 不能为空。");
		}
		if (!ValidationUtils.isMobilePhone(this.getMobilePhone())) {
			ExceptionUtils.throwInvalidCastException(this.getMobilePhone() + " 不是有效的手机号码。");
		}
	}

}
